Skip to contents

Simulation Algorithm Implementations

Core functions to perform a redistricting simulation

redist_smc()
SMC Redistricting Sampler (McCartan and Imai 2023)
redist_mergesplit()
Merge-Split/Recombination MCMC Redistricting Sampler (Carter et al. 2019)
redist_mergesplit_parallel()
Parallel Merge-Split/Recombination MCMC Redistricting Sampler
redist_flip()
'Flip' Markov Chain Monte Carlo Redistricting Simulation (Fifield et al. 2020)
redist_shortburst()
Redistricting Optimization through Short Bursts
redist_constr()
Set up constraints for sampling
add_constr_status_quo() add_constr_grp_pow() add_constr_grp_hinge() add_constr_grp_inv_hinge() add_constr_compet() add_constr_incumbency() add_constr_splits() add_constr_multisplits() add_constr_total_splits() add_constr_pop_dev() add_constr_segregation() add_constr_polsby() add_constr_fry_hold() add_constr_log_st() add_constr_edges_rem() add_constr_custom()
Sampling constraints
redist.crsg()
Redistricting via Compact Random Seed and Grow Algorithm
redist.mcmc.mpi()
MCMC Redistricting Simulator using MPI
redist.rsg()
Redistricting via Random Seed and Grow Algorithm
redist_flip_anneal()
Flip MCMC Redistricting Simulator using Simulated Annealing

Analysis Functions

Functions for analyzing simulation outputs

redist_plans()
A set of redistricting plans
summary(<redist_plans>)
Diagnostic information on sampled plans
add_reference()
Add a reference plan to a set of plans
subset_sampled() subset_ref()
Subset to sampled or reference draws
get_plans_matrix() as.matrix(<redist_plans>)
Extract the matrix of district assignments from a redistricting simulation
get_plans_weights() weights(<redist_plans>)
Extract the sampling weights from a redistricting simulation.
number_by()
Renumber districts to match a quantity of interest
pullback()
Pull back plans to unmerged units
match_numbers()
Renumber districts to match an existing plan
tally_var()
Tally a variable by district
classify_plans()
Hierarchically classify a set of redistricting plans
compare_plans()
Make a comparison between two sets of plans
is_county_split()
Identify which counties are split by a plan
last_plan()
Extract the last plan from a set of plans
min_move_parity()
Calculates Sparse Population Moves to Minimize Population Deviation
plans_diversity()
Calculate the diversity of a set of plans
plot(<redist_classified>)
Plot a plan classification
prec_assignment()
Extract the district assignments for a precinct across all simulated plans
prec_cooccurrence()
Compute a matrix of precinct co-occurrences
proj_distr() proj_avg() proj_contr()
Calculate Projective Distributions, Averages, and Contrasts for a Summary Statistic
rbind(<redist_plans>)
Combine multiple sets of redistricting plans
distr_compactness() redist.compactness()
Calculate compactness measures for a set of plans
competitiveness() redist.competitiveness()
Compute Competitiveness
plan_distances() redist.distances()
Compute Distance between Partitions
redist.district.splits()
Counts the Number of Counties within a District
group_frac() redist.group.percent()
Calculate Group Proportion by District
partisan_metrics() redist.metrics()
Calculate gerrymandering metrics for a set of plans
redist.multisplits()
Counts the Number of Counties Split Between 3 or More Districts
muni_splits() redist.muni.splits()
Counts the Number of Municipalities Split Between Districts
redist.parity() plan_parity()
Calculates Maximum Deviation from Population Parity
segregation_index() redist.segcalc()
Segregation index calculation for MCMC redistricting.
county_splits() redist.splits()
Count County Splits
redist_ci() redist_smc_ci() redist_mcmc_ci()
Confidence Intervals for SMC and MCMC Estimates

Setup Helpers

Functions that help prepare data and select constraints

redist_map() as_redist_map()
Create a redist_map object.
get_adj() set_adj()
Get and set the adjacency graph from a redist_map object
get_existing()
Extract the existing district assignment from a redist_map object
get_pop_tol() set_pop_tol()
Get and set the population tolerance from a redist_map object
get_target()
Extract the target district population from a redist_map object
is_contiguous()
Check that a redist_map object is contiguous
merge_by()
Merge map units
plot(<redist_constr>)
Visualize constraints
plot(<redist_map>)
Plot a redist_map
redist.coarsen.adjacency()
Coarsen Adjacency List
redist.constraint.helper()
Create Constraints for SMC
redist.county.id()
Create County IDs
redist.county.relabel()
Relabel Discontinuous Counties
redist.find.target()
Find Majority Minority Remainder
redist.findparams()
Run parameter testing for redist_flip
freeze() redist.freeze()
Freeze Parts of a Map
make_cores() redist.identify.cores()
Identify Cores of a District (Heuristic)
redist.plot.penalty()
(Deprecated) Visualize Group Power Penalty
redist.reduce.adjacency()
Reduce Adjacency List
redist.sink.plan()
Sink Plans to 1:ndists
redist.subset()
Subset a shp
`*`(<redist_scorer>) `+`(<redist_scorer>) `-`(<redist_scorer>)
Scoring function arithmetic
combine_scorers() cbind(<redist_scorer>)
Combine scoring functions
scorer_group_pct() scorer_pop_dev() scorer_splits() scorer_multisplits() scorer_frac_kept() scorer_polsby_popper() scorer_status_quo()
Scoring functions for redist_shortburst

Plotting Tools

Functions for creating plots and maps

plot(<redist_map>)
Plot a redist_map
plot(<redist_plans>)
Summary plots for \link{redist_plans}
redist.diagplot()
Diagnostic plotting functionality for MCMC redistricting.
redist.plot.adj()
Creates a Graph Overlay
redist.plot.contr_pfdr()
Plot a Projective Contrast with positive False Discovery Rate (pFDR) Control
redist.plot.cores()
Plot Cores
redist.plot.distr_qtys()
Plot quantities by district
redist.plot.hist() hist(<redist_plans>)
Plot a histogram of a summary statistic
redist.plot.majmin()
Majority Minority Plots
redist.plot.map()
Plot a Map
redist.plot.plans()
Plot a district assignment
redist.plot.scatter()
Scatter plot of plan summary statistics
redist.plot.trace()
Make a traceplot for a summary statistic
redist.plot.varinfo()
Static Variation of Information Plot

Data

Data included to help demonstrate capabilities

EPSG
EPSG Table
fl25
Florida 25 Precinct Shape File
fl250
Florida 250 Precinct Shape File
fl25_adj
Florida 25 Precinct File
fl25_enum
All Partitions of 25 Precincts into 3 Congressional Districts (No Population Constraint)
fl70
Florida 70 Precinct Shape File
iowa
Iowa County File

Post Processing Helpers

Functions that help setup outputs for easier use

redist.combine.mpi()
Combine successive runs of redist.mcmc.mpi
redist.ipw()
Inverse probability reweighting for MCMC Redistricting
redist.smc_is_ci()
(Deprecated) Confidence Intervals for Importance Sampling Estimates
redist.uncoarsen()
Uncoarsen a District Matrix

Enumeration Tools

Functions for more involved enumeration choices

redist.calc.frontier.size()
Calculate Frontier Size
redist.enumpart()
Enumerate All Parititions (Fifield et al. 2020)
redist.init.enumpart()
Initialize enumpart
redist.prep.enumpart()
Prepares a run of the enumpart algorithm by ordering edges
redist.read.enumpart()
Read Results from enumpart
redist.run.enumpart()
Runs the enumpart algorithm

Miscellaneous

Other functions

redist-package redist
redist: Simulation Methods for Legislative Redistricting
avg_by_prec()
Average a variable by precinct (Deprecated)
get_mh_acceptance_rate()
Extract the Metropolis Hastings Acceptance Rate
get_sampling_info()
Extract the sampling information from a redistricting simulation
pl()
Access the Current redist_plans() Object
plot(<redist_map>)
Plot a redist_map
print(<redist_classified>)
Print redist_classified objects
print(<redist_constr>)
Generic to print redist_constr
print(<redist_map>)
Generic to print redist_map
print(<redist_plans>)
Print method for redist_plans
redist.adjacency()
Adjacency List functionality for redist
redist.dist.pop.overlap()
Compare the Population Overlap Across Plans at the District Level
redist.plot.wted.adj()
Plot Weighted Border Adjacency
redist.prec.pop.overlap()
Compare the Population Overlap Across Plans at the Precinct Level
redist.random.subgraph()
Return a random subgraph of a shape
redist.reorder()
Reorders district numbers
redist.wted.adj()
Create Weighted Adjacency Data
redist_quantile_trunc()
Helper function to truncate importance weights